package com.fluxtah.jordl.examples.twitter;

import com.fluxtah.jordl.lib.Transformer;
import com.fluxtah.jordl.lib.TransformException;
import org.json.JSONObject;
import org.json.JSONException;

public class TweetOutputTransformer extends Transformer<Tweet, JSONObject> {
	public void transform(Tweet source, JSONObject target) throws TransformException {
		try {
			target.putOpt("created_at", source.getCreatedAt());
			target.putOpt("favorited", source.isFavorited());
			target.putOpt("id", source.getId());
			target.putOpt("id_str", source.getIdStr());
			target.putOpt("in_reply_to_screen_name", source.getInReplyToScreenName());
			target.putOpt("in_reply_to_status_id", source.getInReplyToStatusId());
			target.putOpt("in_reply_to_status_id_str", source.getInReplyToStatusIdStr());
			target.putOpt("in_reply_to_user_id", source.getInReplyToUserId());
			target.putOpt("in_reply_to_user_id_str", source.getInReplyToUserIdStr());
			target.putOpt("possibly_sensitive", source.isPossiblySensitive());
			target.putOpt("retweet_count", source.getRetweetCount());
			target.putOpt("retweeted", source.isRetweeted());
			target.putOpt("source", source.getSource());
			target.putOpt("text", source.getText());
			target.putOpt("truncated", source.isTruncated());
			if(source.getUser() != null) {
				JSONObject targetMember = new JSONObject();
				provider.get(TwitterUserOutputTransformer.class).transform(source.getUser(), targetMember);
			}
		} catch (JSONException x) {
			throw new TransformException(x);
		}
	}
}
